package com.tao.graduation.Controller;

import com.tao.graduation.Pojo.*;
import com.tao.graduation.Service.PatientService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("/patient")
public class PatientController {

    @Autowired
    private PatientService patientService;

    @RequestMapping("/queryPatientByUsername")
    public Map queryPatientByUsername(@RequestBody Integer id){
        Patient patient=patientService.queryPatientByUsername(id);
        Map<String,Object> map=new HashMap<>();
        map.put("data",patient);
        return map;
    }

    @RequestMapping("/queryOption")
    public Map queryOption(){
        Map<String,Object> map=new HashMap<>();
        List<Option> list=patientService.queryOption();
        map.put("data",list);
        return map;
    }

    @RequestMapping("/queryDoctorByOptionType")
    public Map queryDoctorByOptionType(@RequestBody String name){
        Map<String,Object> map=new HashMap<>();
        List<Doctor> list=patientService.queryDoctorByOptionType(name);
        map.put("data",list);
        return map;
    }

    @RequestMapping("/Appointment")
    public Map Appointment(@RequestBody Appointment appointment){
        Map<String,Object> map=new HashMap<>();
//        Appointment info=new Appointment(appointment.getPatientId(),appointment.getDoctorId(),appointment.getTime(),appointment.getExpenses());
        Integer count=patientService.Appointment(appointment );
        if (count>0){
            map.put("message","预约成功!");
        }else {
            map.put("message","预约失败!");
        }
        return map;
    }

    @RequestMapping("/AppointmentRecord")
    public Map AppointmentRecord(@RequestBody Integer id){
        Map<String,Object> map=new HashMap<>();
        List<Map<String,String>> list=patientService.AppointmentRecord(id);
        map.put("data",list);
        return map;
    }

    @RequestMapping("/queryPatientInfo")
    public Map queryPatientInfo(@RequestBody Integer id){
        Map<String,Object> map=new HashMap<>();
        Map<String,String> info=patientService.queryPatientInfo(id);
        map.put("data",info);
        return map;
    }

    @RequestMapping("/queryDoctor")
    public Map queryDoctor(){
        Map<String,Object> map=new HashMap<>();
        List<Doctor> list=patientService.queryDoctor();
        map.put("data",list);
        return map;
    }

    @RequestMapping("/CanOrder")
    public Map CanOrder(@RequestBody Integer id){
        Map<String,Object> map=new HashMap<>();
        Integer count=patientService.CanOrder(id);
        if(count>0){
            map.put("message","预约已取消!");
        }else {
            map.put("message","取消失败!");
        }
        return map;
    }

    @RequestMapping("/insertSelfInfo")
    public Map insertSelfInfo(String name,Integer age,String certId,String address,String sex,Integer id){
        Map<String,Object> map=new HashMap<>();
        Patient patient=new Patient(name,age,certId,sex,address,id);
        Integer count=patientService.insertSelfInfo(patient);
        if (count>0){
            map.put("message","修改成功");
        }else {
            map.put("message","修改失败!");
        }
        return map;
    }
}
